{extend name='public/_home' /}

{block name='title'}文章列表{/block}

{block name='main'}
        <!-- Page Content -->
        <div class="page-content">
            <!-- Page Breadcrumb -->
            <div class="page-breadcrumbs">
                <ul class="breadcrumb">
                    <li>
                        <i class="fa fa-home"></i>&nbsp;文章管理
                    </li>
                    <li>文章列表</li>
                </ul>
            </div>
            <!-- /Page Breadcrumb -->
            <!-- Page Body -->
            <div class="page-body">
                <a href="articleadd.html" class="btn btn-sm btn-primary"><i class="fa fa-plus"></i>&nbsp;添加文章</a>
                <div class="row">
                    <div class="col-xs-12">
                        <div class="widget">
                            <div class="widget-header">
                                <span class="widget-caption">添加文章</span>
                                <div class="widget-buttons">
                                    {$articleInfo|raw|replace}
                                </div>
                            </div>
                            <div class="widget-body">
                                <table class="table table-hover table-bordered">
                                    <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>文章标题</th>
                                        <th>所属导航</th>
                                        <th>是否推荐</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    {volist name='articleInfo' id='vo'}
                                    <tr>
                                        <td>{$vo.id}</td>
                                        <td>{$vo.title}</td>
                                        <td>{$vo.cate_list.catename}</td>
                                        <td>{$vo.is_top ? '推荐' : '未推荐'}</td>
                                        <td>
                                            <!--                                            btn-primary-->
                                            <a href="#"
                                               class="btn btn-sm btn-{$vo.is_top ? 'darkorange' : 'primary'} is_top"
                                               istop="{$vo.is_top}" dataid="{$vo.id}">{$vo.is_top ? '取消推荐' : '推荐'}</a>
                                            <a href="{:url('admin/article/edit?id='.$vo.id)}" class="btn btn-sm btn-warning">编辑</a>
                                            <a href="#" class="btn btn-sm btn-danger article-del" dataid="{$vo.id}">删除</a>
                                        </td>
                                    </tr>
                                    {/volist}
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /Page Body -->
        </div>
        <!-- /Page Content -->

{/block}
{block name="js"}
<script>
    $(function () {
        //是否推荐
        $('.is_top').click(function () {
            var id = $(this).attr('dataid');
            var is_top = $(this).attr('istop');
            var msg = is_top == 1 ? '确定取消推荐？' : '确定推荐？';
            layer.confirm(msg, {
                icon: 3
            }, function () {
                layer.close();
                $.ajax({
                    url: "{:url('admin/article/top')}",
                    type: "post",
                    data: {
                        id,
                        is_top: is_top == 1 ? 0 : 1
                    },
                    dataType: "json",
                    success: function (data) {
                        if (data.code == 1) {
                            layer.msg(data.msg, {
                                icon: 6,
                                time: 2000
                            }, function () {
                                location.href = data.url
                            })
                        } else {
                            layer.open({
                                title: "操作失败",
                                icon: 5,
                                content: data.msg
                            })
                        }
                    }
                })
            })
        });
        //删除
        $('.article-del').click(function () {
            var id = $(this).attr('dataid');
            layer.confirm('确定删除？',{
                icon: 3
            },function () {
                layer.close();
                $.ajax({
                    url: "{:url('admin/article/del')}",
                    type: "post",
                    data: {id},
                    dataType: 'json',
                    success: function (data) {
                        if (data.code == 1) {
                            layer.msg(data.msg, {
                                icon: 6,
                                time: 2000
                            }, function () {
                                location.href = data.url
                            })
                        } else {
                            layer.open({
                                title: "操作失败",
                                icon: 5,
                                content: data.msg
                            })
                        }
                    }
                })
            })
        });
    })
</script>
{/block}
